package com.ybwh.springboot2.uidgen.controller;

import com.ybwh.springboot2.common.RespData;
import com.ybwh.springboot2.uidgen.service.WorkerNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


@Api(tags = "ID生成器")
@Controller
@RequestMapping("/")
public class UidGeneratorController {

    @Autowired
    private WorkerNodeService workerNodeService;


    @ApiOperation(value = "百度ID生成器", notes = "")
    @ResponseBody
    @GetMapping("/getUid")
    public RespData<Long> getUid() {
        return RespData.successResp(workerNodeService.genUid());
    }


    @ApiOperation(value = "上传文件", notes = "")
    @ResponseBody
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public RespData upload(@ApiParam(value = "上传文件", required = true) @RequestParam("file") MultipartFile file)
            throws IllegalStateException, IOException {


        file.transferTo(new File("D:/tmp/" + file.getOriginalFilename()));


        return RespData.successResp(null);

    }


}
